home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / cw_clr_index.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  148 lines

  1. ; $Id: cw_clr_index.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:    
  7. ;    CW_CLR_INDEX
  8. ;
  9. ; PURPOSE:
  10. ;    CW_CLR_INDEX is a compound widget for the selection of a color
  11. ;    index. A horizontal color bar is displayed. Clicking on the bar sets
  12. ;    the color index.
  13. ;
  14. ; CATEGORY:
  15. ;    Compound Widgets
  16. ;
  17. ; CALLING SEQUENCE:
  18. ;    Widget = CW_CLR_INDEX(Parent)
  19. ;
  20. ; INPUTS:
  21. ;    Parent:          ID of the parent widget.
  22. ;
  23. ; KEYWORD PARAMETERS:
  24. ;    COLOR_VALUES: A vector of color indices containing the colors to
  25. ;              be displayed in the color bar. If omitted, NCOLORS
  26. ;              and START_COLOR specify the range of color indices.
  27. ;    EVENT_FUNCT:  The name of an optional user-supplied event function.
  28. ;              This function is called with the return value structure
  29. ;              whenever a button is pressed, and follows the conventions ;              for user-written event functions.
  30. ;    FRAME:        If set, a frame will be drawn around the widget.
  31. ;    LABEL:        A text label that appears to the left of the color bar.
  32. ;    NCOLORS:      The number of colors to place in the color bar.  
  33. ;              The default = !D.N_COLORS.
  34. ;    START_COLOR:  The starting color index, placed at the left of the bar.
  35. ;    UVALUE:       The user value to be associated with the widget.
  36. ;    XSIZE:        The width of the color bar in pixels. The default =192.
  37. ;    YSIZE:        The height of the color bar in pixels. The default = 12.
  38. ;
  39. ; OUTPUTS:
  40. ;       The ID of the created widget is returned.
  41. ;
  42. ; SIDE EFFECTS:
  43. ;    This widget generates event structures with the following definition:
  44. ;
  45. ;    Event = { CW_COLOR_INDEX, ID: base, TOP: ev.top, HANDLER: 0L, VALUE: c}
  46. ;    Value is the color index selected.
  47. ;
  48. ; PROCEDURE:
  49. ;    Standard Compound widget.  Use WIDGET_CONTROL, SET_VALUE and GET_VALUE
  50. ;    to change/read the widget's value.
  51. ;
  52. ; EXAMPLE:
  53. ;    A = WIDGET_BASE(TITLE='Example', /COLUMN)
  54. ;    B = CW_CLR_INDEX(A, LABEL='Color:')
  55. ;
  56. ; MODIFICATION HISTORY:
  57. ;    DMS,    June, 1993.    Written.
  58. ;    TAC,    Oct, 1993.    Changed name to cw_clr_index
  59. ;-
  60.  
  61. function CW_COLOR_INDEXE, ev        ;Color index widget's event proc
  62. if ev.press ne 0 then return, 0
  63. base = ev.handler
  64. widget_control, widget_info(base, /child), get_uvalue = state
  65. c = long(state.start_color + (ev.x * state.scale))  ;New color
  66. if state.extra ne 0L then BEGIN
  67.     WIDGET_CONTROL, state.extra, GET_UVALUE=cv
  68.     c = cv[c]
  69.     endif
  70. CW_COLOR_INDEXS, base, c    
  71. ret =  { CW_COLOR_INDEX, ID: base, TOP: ev.top, HANDLER: 0L, VALUE: c}
  72. if state.efun eq '' then return, ret $
  73. else return, CALL_FUNCTION(state.efun, ret)
  74. end
  75.  
  76.  
  77. function CW_COLOR_INDEXG, id
  78.     widget_control, widget_info(id, /child), get_uvalue = state
  79.     return, state.value
  80. end
  81.  
  82.  
  83. pro CW_COLOR_INDEXS, id, value        ;Set color index widget value
  84. widget_control, (draw = widget_info(id, /child)), get_uvalue = state, /NO_COPY
  85. old_win = !d.window
  86.  
  87. if state.inited eq 0 then begin
  88.     widget_control, state.pwin_id, get_value = i
  89.     wset, i
  90.     x = long(state.scale * findgen(!d.x_size))    ;0 to n_colors-1
  91.     if state.extra ne 0L then begin
  92.     WIDGET_CONTROL, state.extra, GET_UVALUE=cv
  93.     x = cv[x]
  94.     ENDIF
  95.     tv, x # replicate(1, !d.y_size) + state.start_color
  96.     state.inited = 1
  97.     endif
  98.  
  99. state.value = value            ;Save new value
  100. widget_control, state.rect_id, get_value = i
  101. wset, i
  102. tv, replicate(value, !d.x_size, !d.y_size)
  103. wset, old_win
  104. widget_control, state.txt_id, set_value = '(' + strtrim(value,2) + ')'
  105. widget_control, draw, set_uvalue = state, /NO_COPY
  106. return
  107. end
  108.  
  109.  
  110. function CW_CLR_INDEX, parent, LABEL = label, FRAME = frame, $
  111.     UVALUE = uvalue, XSIZE = xsize, YSIZE = ysize, NCOLORS = ncolors, $
  112.     START_COLOR = start_color, EVENT_FUNC = efun, COLOR_VALUES = cv
  113.  
  114. if n_elements(frame) eq 0 then frame = 0
  115. if n_elements(uvalue) eq 0 then uvalue = 0
  116. if n_elements(xsize) eq 0 then xsize = 192
  117. if n_elements(ysize) eq 0 then ysize = 12
  118. if n_elements(cv) gt 0 then begin
  119.     ncolors = n_elements(cv)
  120.     start_color = 0
  121.     endif
  122. if n_elements(ncolors) eq 0 then ncolors = !d.N_COLORS
  123. if n_elements(start_color) eq 0 then start_color = 0
  124. if n_elements(label) eq 0 then label = ''
  125.  
  126. base = widget_base(parent, /ROW, FRAME = frame, $
  127.     EVENT_FUNC = 'CW_COLOR_INDEXE', FUNC_GET_VALUE = 'CW_COLOR_INDEXG', $
  128.     PRO_SET_VALUE = 'CW_COLOR_INDEXS', UVALUE = uvalue)
  129. if n_elements(efun) le 0 then efun = ''
  130. state = { CW_C_INDEX_STATE, $
  131.     txt_id : 0L, rect_id : 0L, pwin_id : 0L, inited : 0, efun: efun, $
  132.     scale : float(ncolors) / xsize, value : 0L, $
  133.     start_color : long(start_color), extra: 0L }
  134. child = widget_label(base, value = label)
  135. state.txt_id = widget_text(base, xsize=5, ysize = 1, value = '(0)')
  136. if n_elements(cv) gt 0 then BEGIN
  137.     WIDGET_CONTROL, state.txt_id, SET_UVALUE=cv
  138.     state.extra = state.txt_id
  139.     endif
  140.  
  141. state.rect_id = widget_draw(base, /FRAME, XSIZE = 16, YSIZE = ysize, $
  142.     UVALUE = 0, RETAIN=2)
  143. state.pwin_id = widget_draw(base, /frame, xsize = xsize, $
  144.     ysize = ysize, /BUTTON)
  145. widget_control, child, set_uvalue = state
  146. return, base
  147. end
  148.